package cn.kevinking.ai.mcp.provider;

import cn.kevinking.ai.common.constant.McpProviderConstants;
import cn.kevinking.ai.common.model.ToolDefinition;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import org.springframework.boot.autoconfigure.web.ServerProperties;

import java.util.List;

/**
 * @author kevinking
 */
@Data
@Builder
public class McpProvider {
	private String name;
	private String description;
	private ProviderServlet servlet;
	private List<ToolDefinition> tools;

	@Data
	@AllArgsConstructor
	public static class ProviderServlet {
		private String ip;
		private Integer port;
		private String path;

		public static ProviderServlet newServlet(ServerProperties serverProperties) {
			String contextPath = serverProperties.getServlet().getContextPath();
			contextPath = McpProviderConstants.DEFAULT_CONTEXT_PATH.equals(contextPath) ? "" : contextPath;
			return new ProviderServlet(serverProperties.getAddress().getHostAddress(), serverProperties.getPort(), contextPath);
		}
	}
}
